﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;


namespace BHair.kucunpandian
{
    public partial class frmrizhi : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public frmrizhi()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void frmrizhi_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtneirong.Text == string.Empty)
            {
                string sql = string.Format("SELECT [id] ,[操作员]  ,[操作内容]  ,[操作时间] FROM [BHairDB].[dbo].[操作日志] where 操作时间>='{0} 0:00:00' and 操作时间<='{1} 23:59;59'  order by id", dtpbegin.Text, dtpend.Text);
                SqlConnection conn = new SqlConnection(constr);
                conn.Open();
                // SqlCommand comm = new SqlCommand(sql,conn);
                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                dataGridView1.DataSource = dt;
                conn.Close();
            }
            else
            {
                string sql = string.Format("SELECT [id] ,[操作员]  ,[操作内容]  ,[操作时间] FROM [BHairDB].[dbo].[操作日志] where 操作时间>='{0} 0:00:00' and 操作时间<='{1} 23:59:59' and 操作内容 like '%{2}%'  order by id", dtpbegin.Text, dtpend.Text,txtneirong.Text);
                SqlConnection conn = new SqlConnection(constr);
                conn.Open();
                // SqlCommand comm = new SqlCommand(sql,conn);
                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                dataGridView1.DataSource = dt;
                conn.Close();
            }

        }
    }
}
